//#########################################################################
//                              WackiEngie
//           Copyright (c) 2014 Marc Wacker. All rights reserved.
//#########################################################################

#pragma once

#include "WeUtilPrerequisites.h"

namespace WackiEngine
{

	class Timer
	{
	public:
		Timer();

		//	Return ticks/second. 
		inline int64 frequency() const { return _freq; }

		// Return number of ticks elapsed since the previous call to update().
		// (number of ticks/second can be queried by calling frequency()).
		inline int64 ticks() const { return _ticks; }

		// Return total number of ticks elapsed since the clock was initialized
		// or since the previous call to \c reset(). 
		inline int64 totalTicks() const { return _totalTicks; }

		//	Return number of seconds elapsed since the previous call to update(). 
		inline double seconds() const { return _seconds; }

		// Return total number of seconds elapsed since the clock was initialized
		// or since the previous call to reset(). 
		inline double totalSeconds() const { return _totalSeconds; }

		// update the results
		void update();

		// reset the data
		void reset();

	private:

		// Ticks since previous call to udpate().
		int64 _ticks;

		// Ticks returned in previous two calls to update().
		int64 _cticks;
		int64 _pticks;

		// Total ticks since clock initialized or previous call to reset(). 
		int64 _totalTicks;

		// Ticks/second.
		int64 _freq;

		// 1/freq_
		double _rfreq;

		// Seconds since previous call to update().
		double _seconds;

		// Total seconds since clock initialized or previous call to reset().
		double _totalSeconds;

	};

}